using System;
using System.Collections.Generic;
using System.Linq;
using Jacobi.Vst.Interop.Host;
using Play.TrackManagement;

namespace Play.AudioEngine
{
	public class AudioRack
	{
		private readonly Func<VstPluginContext, Channel> _channelFactory;
		private readonly List<Channel> _channels = new List<Channel>();

		public AudioRack(Func<VstPluginContext, Channel> channelFactory)
		{
			_channelFactory = channelFactory;
		}

		public IEnumerable<Channel> GetChannelsCopy()
		{
			lock (_channels)
				return _channels.ToList();
		}

		public void HandleMessage(TrackCreatedMessage message)
		{
			var channel = _channelFactory(message.Track.PluginContext);
			lock (_channels)
				_channels.Add(channel);
		}
	}
}